<template>
    <div>
        <h1>修改页面</h1>
    </div>
    <table class="table">
        <tbody>
            <tr>
                <td>上传图片</td>
                <td>
                    <input type="file" @change="upload">
                    <img :src="axios.defaults.baseURL+data.Img" style="width: 60px;">
                </td>
            </tr>
            <tr>
                <td>编号</td>
                <td><input type="text" v-model="data.Bh" disabled></td>
            </tr>
            <tr>
                <td>姓名</td>
                <td><input type="text" v-model="data.Name"></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password" v-model="data.Password"></td>
            </tr>
            <tr>
                <td>生日</td>
                <td><input type="date" v-model="data.BirthDay"></td>
            </tr>
            <tr>
                <td>年龄</td>
                <td><input type="text" v-model="data.Age"></td>
            </tr>
            <tr>
                <td>状态</td>
                <td>
                    <select v-model="data.sid">
                        <option value="0">请选择状态</option>
                        <option v-for="d in bangdata":value="d.Sid">{{d.StateName}}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>性别</td>
                <td>
                    <input type="radio" name="sexs" value="男">男
                    <input type="radio" name="sexs" value="女">女
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="修改" @click="update">
                </td>
            </tr>
        </tbody>
    </table>
</template>

<script setup lang="ts">
import axios from 'axios';
import {ref,onMounted} from 'vue';
import { useRouter,useRoute } from 'vue-router';
const router=useRouter();
const route=useRoute();
onMounted(() => {
    bang();
    ft();
})
const bangdata=ref({})
const bang=()=>{
    axios.get("/api/State/GetStates",{params:bangdata.value}).then(res=>{
        bangdata.value=res.data
    })
}
const upload=(ev:any)=>{
    let f=ev.target.files[0];
    let fd=new FormData();


    fd.append("file",f);

    axios.post("/api/UploadFiles/Upload",fd).then(res=>{
        data.value.Img=res.data;
    })

}
const ft=()=>{
    let mid=route.query.Id;
    axios.get("/api/Member/Ft",{params:{Id:mid}}).then(res=>{
        data.value=res.data
    })
}
const data=ref({
    "Id": 0,
  "Bh": "",
  "Name": "",
  "Password": "",
  "BirthDay": "",
  "Age": 0,
  "Img": "string",
  "sid": 0,
  "Sex": 0,
  "IsDelete": true
})
const update=()=>{

    axios.post("/api/Member/UpdateMember",data.value).then(res=>{
        if(res.data>0)
        {
            alert('修改成功')
            router.push('/');
        }
        else
        {
            alert('修改失败')
            return;
        }
    })
}







</script>

<style scoped>

</style>